<?php
/**
 * Created by PhpStorm.
 * User: 小夏
 * Date: 2016/9/30 0030
 * Time: 14:47
 */

namespace Invest\Controller;
use Common\Controller\AdminbaseController;
class AdminOrderController extends AdminbaseController
{
    protected $ordergoods;
    protected $orderinfo;
    function _initialize() {
        parent::_initialize();
        $this->ordergoods = M("OrderGoods");
        $this->orderinfo = M("OrderInfo");
    }
    public function index(){
        $where = array();
        $order_sn = I('request.order_sn');
        if (!empty($order_sn)){
            $where['order_sn'] = $order_sn;
        }
        $count = $this->orderinfo->where($where)->count();// 查询满足要求的总记录数
        $Page  = $this->Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $this->orderinfo->where($where)->order('order_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();

        if($list){
            $uids=array();
            $gids=array();
            foreach ($list as $id){
                array_push($uids,$id['user_id']);
                array_push($gids,$id['order_id']);
            }
            //用户名查询
            $uname= M('Users')->where(array('id'=>array('in',$uids)))->getField('id,user_nicename');
            //商品名查询
           $goods = $this->ordergoods->where(array('order_id'=>array('in',$gids)))->select();

            foreach ($list as $key=>$value){
                $list[$key]['uname'] = $uname[$value['user_id']];
                foreach ($goods as $k=>$v){
                   if($v['order_id'] == $value['order_id']){
                       $list[$k]['goods_name']= $v['goods_name'];
                   }
                }
            }
        }
        $this->assign('list',$list);// 赋值数据集
        $this->assign("formget",array_merge($_GET,$_POST));
        $this->assign("page", $Page->show('Admin'));
        $this->display();
    }
    function testsms(){
        $sms = smsinterface('13760641086','123456');
        $resultsms = xmlToArray($sms);
        echo '<pre>';
        print_r($resultsms);exit;
    }
}